package com.example.ymm.modules1.service.impl.hl.ex;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.ymm.base.BaseServiceImpl;
import com.example.ymm.model.TableList;
import com.example.ymm.model.YmPageDto;
import com.example.ymm.modules1.entity.hl.ex.ExQuestionOption;
import com.example.ymm.modules1.mapper.ex.ExQuestionOptionMapper;
import com.example.ymm.modules1.query.hl.ex.ExQuestionOptionQueryCriteria;
import com.example.ymm.modules1.service.hl.ex.ExQuestionOptionService;
import com.example.ymm.util.QueryHelpPlus;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@Slf4j
@DS("slave2")
public class ExQuestionOptionServiceImpl extends BaseServiceImpl<ExQuestionOptionMapper, ExQuestionOption> implements ExQuestionOptionService {

    @Override
    public TableList<ExQuestionOption> list(ExQuestionOptionQueryCriteria criteria, YmPageDto pageDto) {
        IPage<ExQuestionOption> page = new Page<ExQuestionOption>(pageDto.getPage(),pageDto.getPageSize());
        QueryWrapper predicate = QueryHelpPlus.getPredicate(ExQuestionOption.class, criteria);
        predicate.orderByAsc("sort");
        baseMapper.selectPage(page, predicate);
        TableList<ExQuestionOption> tableList=new TableList(page);
        return tableList;
    }

    public List<ExQuestionOption> queryAll(ExQuestionOptionQueryCriteria criteria) {
        QueryWrapper predicate = QueryHelpPlus.getPredicate(ExQuestionOption.class, criteria);
        predicate.orderByAsc("sort");
        List<ExQuestionOption> result =baseMapper.selectList(predicate);
        return result;
    }
}
